#include "gtest/gtest.h"

#include "stream/impl/rocksdb/meta/Size.h"
#include "stream/impl/rocksdb/Rocksdb.h"

using Size=stream::impl::rocksdb::meta::Size;
using Rocksdb = stream::impl::rocksdb::Rocksdb;

TEST(MetaSizeTest, test){
	auto db = std::make_shared<Rocksdb>("test-size.db");
	db->createIfMissing();

	Size size(db, 0);
	ASSERT_EQ(0ull, size.get());

	size.inc();
	ASSERT_EQ(1ull, size.get());

	size.dec();
	ASSERT_EQ(0ull, size.get());

	size.inc(2);
	ASSERT_EQ(2ull, size.get());

	size.dec(2);
	ASSERT_EQ(0ull, size.get());

	size.set(10);
	ASSERT_EQ(10ull, size.get());

	db->close();
}

TEST(MetaSizeTest, testLoadStore){
	auto db = std::make_shared<Rocksdb>("test-size.db");
	db->createIfMissing();

	Size size(db, 0);
	ASSERT_EQ(0ull, size.get());
	ASSERT_TRUE(size.load());

	size.set(10);
	ASSERT_TRUE(size.store());

	ASSERT_TRUE(size.load());
	ASSERT_EQ(10ull, size.get());

	db->close();
}
